//
//  NewMainMidView.m
//  QoilPublic
//
//  Created by SunChao on 2018/1/12.
//  Copyright © 2018年 孙超. All rights reserved.
//

#import "NewMainMidView.h"
#import "QLoginVC.h"
#import "BalanceVC.h"
typedef NS_ENUM(NSInteger, TapActionStatus) {
    TapStatusLogin       = 1,
    TapStatusAccount     = 2,
};
@interface NewMainMidView ()

@property (weak,nonatomic)IBOutlet UIImageView *button1;
@property (weak,nonatomic)IBOutlet UIButton *button2;
@property (weak,nonatomic)IBOutlet UIButton *button3;
@property (weak, nonatomic) IBOutlet UIButton *button4;
@property (weak, nonatomic) IBOutlet UILabel *moneyLabel;
@property (weak, nonatomic) IBOutlet UILabel *yuanLabel;
@property (assign,nonatomic)NSInteger status;

@end

@implementation NewMainMidView
- (void)setStatusWithIsLogin:(BOOL)isLogin AccountMoney:(NSString *)money{
    
    if (isLogin) {
        _moneyLabel.hidden = NO;
        _yuanLabel.hidden = NO;
        _moneyLabel.text = money;
        [_moneyLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:23]];
        [_button1 setImage:[UIImage imageNamed:@"New_个人余额"]];
        _status = TapStatusAccount;
    }
    
    else{
        [_button1 setImage:[UIImage imageNamed:@"New_登录"]];
       
        _moneyLabel.hidden = YES;
        _yuanLabel.hidden  = YES;
         _status = TapStatusLogin;
    }
}
-(void)awakeFromNib{
    [super awakeFromNib];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction)];
    [_button1 addGestureRecognizer:tap];
    _button1.contentMode = UIViewContentModeScaleAspectFill;
    _button1.userInteractionEnabled = YES;
    _button1.layer.cornerRadius = 10.0f;
    _button1.layer.shadowColor = [UIColor blackColor].CGColor;
    _button1.layer.shadowOpacity = 0.25f;
    _button1.layer.shadowRadius = 4.f;
    _button1.layer.shadowOffset = CGSizeMake(4,4);
    _button1.contentMode = UIViewContentModeScaleToFill;
    
    _button2.layer.cornerRadius = 10.0f;
    _button2.layer.shadowColor = [UIColor blackColor].CGColor;
    _button2.layer.shadowOpacity = 0.25f;
    _button2.layer.shadowRadius = 4.f;
    _button2.layer.shadowOffset = CGSizeMake(4,4);
    
    
    _button3.layer.cornerRadius = 10.0f;
    _button3.layer.shadowColor = [UIColor blackColor].CGColor;
    _button3.layer.shadowOpacity = 0.25f;
    _button3.layer.shadowRadius = 4.f;
    _button3.layer.shadowOffset = CGSizeMake(4,4);
    
    _button4.layer.cornerRadius = 10.0f;
    _button4.layer.shadowColor = [UIColor blackColor].CGColor;
    _button4.layer.shadowOpacity = 0.25f;
    _button4.layer.shadowRadius = 4.f;
    _button4.layer.shadowOffset = CGSizeMake(4,4);
    
}
- (void)tapAction{
    
    NSLog(@"点击了");
    if (_status == TapStatusLogin) {
        
        QLoginVC *vc = [[QLoginVC alloc] init];
        UIViewController *currentVC = [QViewUtility getCurrentVC];
        [currentVC.navigationController pushViewController:vc animated:YES];
    }
    
    if (_status == TapStatusAccount) {
        
        BalanceVC *vc = [[BalanceVC alloc] init];
        UIViewController *currentVC = [QViewUtility getCurrentVC];
        [currentVC.navigationController pushViewController:vc animated:YES];
    }
   
}
- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if(self){
    }
    return self;
}


#pragma mark ---加油按钮点击方法
- (void)buttonActionAnimationWithButton:(UIButton *)button{
//    button.transform = CGAffineTransformIdentity;
//
//    [UIView animateKeyframesWithDuration:1.0 delay:0 options:0 animations: ^{
//
//        [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:1 / 3.0 animations: ^{
//
//
//
//            button.transform = CGAffineTransformMakeScale(1.5, 1.5);
//
//        }];
//
//        [UIView addKeyframeWithRelativeStartTime:1/3.0 relativeDuration:1/3.0 animations: ^{
//
//
//
//            button.transform = CGAffineTransformMakeScale(0.8, 0.8);
//
//        }];
//
//        [UIView addKeyframeWithRelativeStartTime:2/3.0 relativeDuration:1/3.0 animations: ^{
//
//
//
//            button.transform = CGAffineTransformMakeScale(1.0, 1.0);
//
//        }];
//
//    } completion:^(BOOL finished) {
    
        NSInteger index = button.tag/100;
        [self.delegate DidSelectedButtonAtIndex:index];
        
//    }];
}
#pragma mark ---加油按钮点击方法
- (IBAction)leftButtonAction:(UIButton *)button{
   
    [self buttonActionAnimationWithButton:button];
}
#pragma mark ---智能加油按钮点击方法
- (IBAction)midButtonAction:(UIButton *)button {
    
     [self buttonActionAnimationWithButton:button];
    
}

#pragma mark ---充值按钮点击方法
- (IBAction)rightButtonAction:(UIButton *)button{
   
    [self buttonActionAnimationWithButton:button];
    
}

@end
